package {
	import com.hvilela.nuvem.FuzzyEngine;
	import flash.display.Sprite;

	/**
	 * @author hvilela
	 */
	public class NuvemSample extends Sprite {
		public function NuvemSample() {
			var hot:Function = FuzzyEngine.createLinearMembershipFunction(20, 40);
			var warm:Function = FuzzyEngine.createTriangularMembershipFunction(10, 20, 30);
			var cold:Function = FuzzyEngine.createLinearMembershipFunction(20, 0);

			var functions:Array = [hot, warm, cold];
			var colors:Array = [0xFF0000, 0x009900, 0x0000FF];

			var i:int = 0;
			for each (var func:Function in functions) {
				graphics.moveTo(0, 0);
				graphics.lineStyle(2, colors[i++]);

				for (var t : int = 0; t < 60; t++) {
					graphics.lineTo(t * 10, (1 - func(t)) * 100 + 50 + i + 1);
				}
			}

			graphics.moveTo(0, 0);
			graphics.lineStyle(2, 0x000000);

			for (var t : int = 0; t < 60; t++) {
				var value:Number = FuzzyEngine.eval(
					"(((TEMPERATURE IS HOT) OR (TEMPERATURE IS WARM)) AND NOT (TEMPERATURE IS COLD))",
					{TEMPERATURE:t}, // Input values to be fuzzyficated
					{HOT:hot, WARM:warm, COLD:cold} // Fuzzyfication functions
				);

				FuzzyEngine.toBool(value);

				graphics.lineTo(t * 10, (1 - value) * 100 + 50);
			}		
		}
	}
}